package com.itxiao.controller;

import com.itxiao.entity.Banner;
import com.itxiao.pojo.vo.R;
import com.itxiao.service.BannerService;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@
RestController
@RequestMapping("admin/api/v1/banner")
@Api(tags = "轮播图模块")
@CrossOrigin
public class BannerController extends BaseController<BannerService, Banner>{
   //航旅的微信小程序下单
    /** 商户号 */
    public static String merchantId = "1628511001";
    /** 商户API私钥路径 */
    public static String privateKeyPath = "D:\\qq\\apiclient_key.pem";
    /** 商户证书序列号 */
    public static String merchantSerialNumber = "152BE09DC509711BC9E1C1AC1430B98BBE123AD8";
    /** 商户APIV3密钥 */
    public static String apiV3Key = "hanglvzhenpin1234567891234567891";
    @ApiOperation("测试")
    @PostMapping("/test")
    public R test() {
        // 使用自动更新平台证书的RSA配置
        // 建议将 config 作为单例或全局静态对象，避免重复的下载浪费系统资源
        Config config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(merchantId)
                        .privateKeyFromPath(privateKeyPath)
                        .merchantSerialNumber(merchantSerialNumber)
                        .apiV3Key(apiV3Key)
                        .build();
        // 构建service
        JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
        // request.setXxx(val)设置所需参数，具体参数可见Request定义
        PrepayRequest request = new PrepayRequest();
        Amount amount = new Amount();
        amount.setTotal(100);
        amount.setCurrency("CNY");
        Payer  payer = new Payer();
        payer.setOpenid("orx1t7TFHyr1nB4U2H1XNprpp0pA");
        request.setPayer(payer);
        request.setAmount(amount);
        request.setAppid("wxdb32a0e62b86f886");
        request.setMchid("1628511001");
        request.setDescription("测试商品标题");
        request.setNotifyUrl("https://notify_url");
        request.setOutTradeNo("damiduoduoddo");
        // 调用下单方法，得到应答
        PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
        // 使用微信扫描 code_url 对应的二维码，即可体验Native支付
        System.out.println(response);
        return R.ok();
    }
}
